--竞技场头条
---@class Billboard_ArenaPanel : UIComponentBase
local ArenaPanel = Class("ArenaPanel",UIComponentBase)
local t = ArenaPanel

function t:OnCreate()
    self.rankTxt = self:GetChild("RankNumber")
    self.nameTxt = self:GetChild("PlayerName")
    self.powerTxt = self:GetChild("PowerNumber")
    self.btnRank = self:GetChild("LookRank")
    self.btnReward = self:GetChild("RewardGet")
    self.changeTxt = self:GetChild("change")
    self.head = self:GetChild("head")
    self.headIcon = self:GetChild("head/head/HeadIcon")
    self.headFrame = self:GetChild("frame",self.head)
    self:RegisterOnClick(self.btnRank,self.ClickRank)
    self:RegisterOnClick(self.btnReward,self.ClickReward)
    self:RegisterOnClick(self.head,self.ClickHead)
    self.rankType = logicMgr.NoticeManager.RankType.arena
end

function t:OnEnable()
    self:RefreshAlertPlayer()
    self.changeTxt.text = logicMgr.NoticeManager.GetAbnormalChangeStr(self.rankType)
    self:RefreshReward()
end
function t:RefreshAlertPlayer(player)
    if not player then
        player = logicMgr.NoticeManager.GetAlertPlayer(self.rankType)
    end
    if player then
        self.firstPlayerId = player.playerId
        self.rankTxt.text = player.rank
        self.nameTxt.text = player.name
        self.powerTxt.text = getNumString(player.power)
        self:SetPlayerIcon(self.headIcon,player.headId,self.headFrame,player.headFrame)
    else
        self.firstPlayerId = ""
        self.rankTxt.text = "0"
        self.nameTxt.text =  getLanguage("BillboardRankNeedPlayer")
        self.powerTxt.text = "0"
        self.headIcon.url = EnumConst.AtlasPath.CommonUI.."icon_hero_kb91"
        self.headFrame.url = ""
    end
end
function t:OnDisable()
end
function t:OnDestroy()
end

function t:ClickRank()
    showUI(PanelNames.UIArenaRank)
end
function t:GetAllData()
    local infos = logicMgr.ArenaManager.getRankInfo()
    if not infos or infos.ranks[1] == nil then
        self.changeTxt.text = logicMgr.NoticeManager.GetChangeStr(self.rankType,NoticeManager.NO_MAIN_CHOOSE_TYPE)
        return
    end
    local first = infos.ranks[1]
    if logicMgr.NoticeManager.HasAlertChange(self.rankType) then
        return
    end
    self:RefreshAlertPlayer(first)
    --第一
   -- local str = logicMgr.NoticeManager.GetAbnormalChangeStr2(self.rankType,1)
    --self.changeTxt.text = string.format(str,first.name)
end

function t:RefreshReward()
    self.btnReward.visible = logicMgr.NoticeManager.HasReward(self.rankType)
end
function t:ClickReward()
    NoticeHandler.ReqChangeAwardByType(self.rankType)
end

function t:ClickHead()
    if self.firstPlayerId ~= "" then
        roleInfoHandler.sendreqOtherRoleInfo(self.firstPlayerId);
    end
end

return t